<template>
  <div>
    <el-form   :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="仓库编码" prop="WarehouseNumber">
                <el-input v-model="model.WarehouseNumber"></el-input>
            </el-form-item>

            <el-form-item label="仓库名称" prop="WarehouseName">
                <el-input v-model="model.WarehouseName"></el-input>
            </el-form-item>
             <el-form-item label="位置" prop="Location">
             <el-input v-model="model.Location"></el-input>
            </el-form-item>
              <el-form-item label="面积" prop="Area">
                <el-input v-model="model.Area"></el-input>
            </el-form-item>
            <el-form-item label="负责人" prop="Charge">
                <el-input v-model="model.Charge"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="Remark">
                <el-input type="textarea" :rows="2.5" placeholder="请输入内容" v-model="model.Remark"></el-input>
            </el-form-item>
            <el-form-item class="page-box-footer">
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
  </div>
</template>

<script>
export default {
    props:{
        model:{
            require:true,
            type:Object
        },
        isUpdate:{
            require:true,
            type:Boolean
        }
    },
    data(){
        return{
            WarehouseList:[],
            rules:{
                    WarehouseNumber:{ required: true, message: '请输入仓库编码', trigger: 'blur' },
                    WarehouseName:{ required: true, message: '请输入仓库名称', trigger: 'blur' },
                    Location:{ required: true, message: '请输入位置', trigger: 'blur' },
                    Area:{ required: true, message: '请输入面积', trigger: 'blur' },
                    Charge:{ required: true, message: '请输入负责人', trigger: 'blur' },
                }
        }
    },
    created(){
        this.getWarehouseAll();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid)=>{
                if(valid){
                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }
                }else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm(){
            this.$refs['ruleForm'].resetFields();
        },
         add(){
        this.$http.postForm('/api/Warehouse',{model:this.model},{loading:this.$loading()})
        .then(res=>{
            this.$emit('callback');
        })

      },
      //修改
      put(){
        this.$http.putForm('/api/Warehouse',{model:this.model},{loading:this.$loading()})
		.then((res)=>{
            this.$emit('callback');
		})
      },

      getWarehouseAll(){
        this.$http.get('/api/Warehouse/GetAll')
        .then(res=>{
            this.WarehouseList=res.Data ;
        })
      }
    }
}
</script>

<style>

</style>